package com.working.wanandroid.init

import android.content.Context
import android.view.Menu
import androidx.navigation.NavController
import androidx.navigation.NavGraphBuilder
import androidx.navigation.navigation
import com.alibaba.android.arouter.facade.annotation.Route
import com.working.libbase.initializer.ApplicationProvider
import com.working.wanandroid.R
import org.koin.core.module.Module

@Route(path = "/provider/main")
class MainProviderImpl : ApplicationProvider {
    private val mMenu = arrayListOf<Menu.() -> Unit>()
    private val mDestination = arrayListOf<NavGraphBuilder.() -> Unit>()


    override fun build(navController: NavController) {
        navController.graph =
            navController.navigatorProvider.navigation(R.id.main_nav, R.id.tab_content) {
                mDestination.forEach {
                    it()
                }
            }
    }

    override fun build(menu: Menu) {
        menu.apply {
            mMenu.forEach { it() }
        }
    }

    override fun addDestination(destination: NavGraphBuilder.() -> Unit) {
        mDestination += destination
    }

    override fun addMenu(menu: Menu.() -> Unit) {
        mMenu += menu
    }

    override fun init(context: Context?) {
        mMenu.clear()
        mDestination.clear()
    }

}